package com.kt.service;

import com.kt.dao.*;
import com.kt.po.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SchoolService {
    @Autowired
    private TeacherDao teacherDao;
    @Autowired
    private StudentDao studentDao;
    @Autowired
    private CourseDao courseDao;
    @Autowired
    private TeacherMapper teacherMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private StudentInfoMapper studentInfoMapper;

    public Teacher findTeacherByTid(int tid){
//        Teacher teacher = teacherDao.findTeacherByTid(tid);
//        //过滤student的teacher属性
//        List<Student> students = teacher.getStudents();
//        for (Student student : students) {
//            student.setTeacher(null);
//        }
//        teacher.setStudents(students);
//        return teacher;
        return teacherDao.findTeacherByTid(tid);
    }

    public Student findStudentBySid(int sid){
        return studentDao.findStudentBySid(sid);
    }

    public int deleteTeacherById(int id){
        return teacherMapper.deleteTeacherById(id);
    }

    public int deleteStudentByTid(int tid){
        return studentMapper.deleteStudentByTid(tid);
    }

    public Map<String,Integer> deleteTeacherAndStudentByTid(int id){
        Map<String,Integer> map= new HashMap<>();
        int deleteStudentCount = studentMapper.deleteStudentByTid(id);
        int deleteTeacherCount = teacherMapper.deleteTeacherById(id);
        map.put("deleteStudentCount",deleteStudentCount);
        map.put("deleteTeacherCount",deleteTeacherCount);
        return map;
    }

    public Student findStudentBySidMap(int sid){
        StudentInfo studentInfo = studentInfoMapper.findStudentInfoById(sid);
        Student student = studentMapper.findStudentBySid(sid);
        student.setStudentInfo(studentInfo);
        return student;
    }

    public List<Teacher> findTeacherByIdMap(int id){
        return teacherMapper.findTeacherById(id);
    }

    public List<Course> findAllCourseMap(){
        return courseDao.findAll();
    }

}
